/******************************************
 *Author:庄育龙
 *Function:开始局域网对战对话框的实现，并有处理UDP数据报的能力
 *Created Date:2013.05.22
 *Last Modified:2013.05.28
 ******************************************/

#ifndef NETWORKD_H
#define NETWORKD_H

#include <QDialog>
#include <QUdpSocket>
#include <QtNetwork>
#include <QTimer>

enum MessageType{NewServer,ServerLeft,Allow,Refuse,Join};
namespace Ui {
class networkd;
}

class networkd : public QDialog
{
    Q_OBJECT
    
public:
    explicit networkd(QWidget *parent = 0);
    QString getUserName();
    QString getUserID();
    ~networkd();
    
protected:
    void sendMessage(MessageType type,QString serverAddress="");
    void newServer(QString userName,QString ipAddress);
    void serverLeft(QString userName, QString ipAddress);
signals:
    void newgame(QString userID,QString myIP,QString yourIP,bool iFirst,bool EnableForbidden,bool AllowUndo);

private slots:
    void on_pushButton_3_clicked();

    void on_pushButton_clicked();

    void processPendingDatagrams();

    void on_pushButton_2_clicked();

    void newserver();

private:
    Ui::networkd *ui;
    qint16 port;
    //QString userID;
    QUdpSocket *udpSocket;
    QString setfile;
    bool ServerFirst;
    bool AllowUndo;
    bool IsForbidden;
    QString getIP();
    QTimer timer;
};

#endif // NETWORKD_H
